<?php
/**
 * {Ctrl.php}
 *
 * Author: asuslx (asuslx@gmail.com)
 * Date: 7/1/12
 */
 
class Ctrl extends F_App_Controller {

    protected $params = array(

        'Tickets' => array(

            array('name' => 'subject', 'type' => 'str', 'strict' => false),
            array('name' => 'email', 'type' => 'str', 'strict' => false),
            array('name' => 'phone', 'type' => 'str', 'strict' => false),
            array('name' => 'body', 'type' => 'str', 'strict' => false),
            array('name' => 'captcha', 'type' => 'str', 'strict' => false),
            array('name' => 'submit', 'type' => 'str', 'strict' => false),
        ),
    );

    function _initialize() {

        $this->frame = new Frame_Main();
    }

    protected function onException(Exception $e) {

        var_dump($e);
	    //header ("Location: error.html");
    }
    
    function action404($params) {
	
    }

    function actionIndex($params) {
        
        $this->_assign('content', F_App_ContentManager::get('main_page'));
    }

    function actionPrices($params) {
        $this->_assign('content', F_App_ContentManager::get('prices_page'));
    }

    function actionClients($params) {
        $this->_assign('content', F_App_ContentManager::get('clients_page'));
    }

    function actionContacts($params) {
        $this->_assign('content', F_App_ContentManager::get('contacts_page'));
    }

    function actionTickets($params) {

        $this->_assign('content', F_App_ContentManager::get('tickets_page'));
        $this->_assign('params', $params);

        if(!empty($params['submit'])) {

            if(!F_Tools_Captcha::check($params['captcha'])) {

                $this->_assign("error", "Неверно указан код с картинки!");
            } else {

                if(!Ads_Message::create($params['subject'], $params['email'], $params['phone'], $params['body'])) {

                    $this->_assign("error", Ads_Message::getLastError());
                } else {

                    $this->_assign("success", true);
                }
            }
        }
    }

    function actionViewMessages($params) {

        $messages = Ads_Message::getList();
        if($messages === false) {
            $this->_assign("error", Ads_Message::getLastError());
        } else {
            $this->_assign("messages", $messages);
        }

    }

}
